#!/bin/ksh
#--------------------------------------------------------------
# Script Name : Monitor the Main Scripts 
# Created by  : hartlen
#         on  : 2010.03.11
# Updated by  : 
#         on  : 
# Parameters  : 
# Return Code : 0   = Normal End
# Comments    : 
#--------------------------------------------------------------
MYDATE=`date +%Y-%m-%d`
MYHOST=`hostname`
MYUSER=`whoami`

SAW_Server_check()
{
sawserver_PID=`ps -ef | grep "sawserver.sh" | grep -v grep | awk '{print $2}'`
Flag=Myflag$sawserver_PID
if [ $Flag = Myflag ]
then
  echo
  echo "**********************************************************"
  echo "********* NO  BIEE Presention Server Is running **********"
  echo "**********************************************************"
  echo
else
  TEST=`ps -ef|grep $sawserver_PID | grep -v grep | wc -l`
  echo
  echo "**********************************************************"
  echo 
  echo "************    BIEE SAW  Server Is running    ***********"
  echo "************ And $TEST SAW Process  is running ***********"
  echo 
  echo "**********************************************************"
  echo 
  ps -ef | grep "sawserver.sh" | grep -v grep 
  echo
  echo
  ps -ef|grep $sawserver_PID | grep -v grep | grep -v  "sawserver.sh"
fi
}
Oc4j_Server_check()
{
oc4jserver_PID=`ps -ef | grep "oc4j -start" | grep -v grep | awk '{print $2}'`
Flag=Myflag$oc4jserver_PID
if [ $Flag = Myflag ]
then
  echo
  echo "**********************************************************"
  echo "********* NO Oc4j Container  Server Is running  **********"
  echo "**********************************************************"
  echo
else
  TEST=`ps -ef|grep $oc4jserver_PID | grep -v grep | wc -l`
  echo
  echo "**********************************************************"
  echo
  echo "************    BIEE OC4J Server Is running    ***********"
  echo "************ And $TEST oc4j Process is running ***********"
  echo
  echo "**********************************************************"
  echo
  ps -ef | grep "oc4j -start" | grep -v grep
  echo
  echo
  ps -ef|grep $oc4jserver_PID | grep -v grep | grep -v "oc4j -start"
fi
}

NQS_Server_check()
{
nqsserver_PID=`ps -ef | grep "nqsserver" | grep -v grep | awk '{print $2}'`
Flag=Myflag$nqsserver_PID
if [ $Flag = Myflag ]
then
  echo
  echo "**********************************************************"
  echo "*************  NO BIEE Server Is running          ********"
  echo "**********************************************************"
  echo
else
  echo
  echo "**********************************************************"
  echo
  echo "**********         BIEE  Server Is running       *********"
  echo
  echo "**********************************************************"
  echo
  ps -ef|grep $nqsserver_PID | grep -v grep
fi
}

Informatica_Server_check()
{
Infoserver_PID=`ps -ef | grep "org.apache.catalina.startup.Bootstrap start" | grep -v grep | awk '{print $2}'`
Flag=Myflag$Infoserver_PID
if [ $Flag = Myflag ]
then
  echo
  echo "**********************************************************"
  echo "*********  NO Informatica Server Is running    **********"
  echo "**********************************************************"
  echo
else
  TEST=`ps -ef|grep $Infoserver_PID | grep -v grep | wc -l`
  echo
  echo "**********************************************************"
  echo
  echo "************  Informatica Server Is running    ***********"
  echo "************ And $TEST Info Process is running ***********"
  echo
  echo "**********************************************************"
  echo
  ps -ef | grep "org.apache.catalina.startup.Bootstrap start" | grep -v grep
  echo
  echo
  ps -ef|grep $Infoserver_PID | grep -v grep | grep -v  "org.apache.catalina.startup.Bootstrap start"
fi
}

DAC_Server_check()
{
DACserver_PID=`ps -ef | grep "startserver.sh" | grep -v grep | awk '{print $2}'`
Flag=Myflag$DACserver_PID
if [ $Flag = Myflag ]
then
  echo
  echo "**********************************************************"
  echo "*********      NO DAC Server Is running         **********"
  echo "**********************************************************"
  echo
else
  TEST=`ps -ef|grep $DACserver_PID | grep -v grep | wc -l`
  echo
  echo "**********************************************************"
  echo
  echo "************     DAC  Server Is running        ***********"
  echo "************ And $TEST DAC  Process is running ***********"
  echo
  echo "**********************************************************"
  echo
  ps -ef | grep "startserver.sh" | grep -v grep
  echo
  echo
  ps -ef|grep $DACserver_PID | grep -v grep | grep -v "startserver.sh"
fi
}

instance_check()
{
smon_pid=`ps -ef | grep ora_smon_DWPROD |grep -v grep |awk '{print $2}'`
if [ -z $smon_pid ]
then
  echo
  echo "************DWPROD Instance is not running ***************"
  echo
  echo "*************    Must call SA Or DBA      ****************"
  echo
else
  TEST=`ps -ef|grep oracleDWPROD | grep -v grep | wc -l`
  echo
  echo "************   DWPROD Instance is running *****************"
  echo
  echo "*********  and $TEST Server Process is running   *************"
  echo
  ps -ef|grep oracleDWPROD | grep -v grep
fi
}

ora_tns_check()
{
lsnr_pid=`ps -ef | grep "tnslsnr LISTENER" |grep -v grep |awk '{print $2}'`
if [ -z $lsnr_pid ]
then
  echo
  echo "************ DWPROD Listener is not running ***************"
  echo
  echo "*************     Must call SA Or DBA      ****************"
  echo
else
  echo
  echo "************ DWPROD Listener is running   *****************"
  echo
  ps -ef|grep "tnslsnr LISTENER" | grep -v grep
fi
}



Disk_FileSystem_check()
{
echo  "**********************************************************" 
echo  "                      Disk FileSystem                     "
echo  "**********************************************************"
echo
df -h

}
HardWare_check()
{
  dmesg | grep -e "Error" -e "error" -e "Warn" -e "warn" >/tmp/dmesg.out
  Linesize=`cat /tmp/dmesg.out | wc -l`
  if [ $Linesize -gt 0 ]
  then
    dmesg 
  else
    echo 
    echo "  No Hardware error has found !  "
  fi
}

#---------------------------------------
#   Here is the menu !
#---------------------------------------

while :
do
tput clear
cat <<EOF
    ------------------------------------------------------------------------
    User:$MYUSER         Host:$MYHOST     Siebel system         Date:$MYDATE            
    ------------------------------------------------------------------------
                          1: BIEE Server Check
                          2: BIEE SAW Server Check
                          3: BIEE OC4J Server check
                          4: Informatica Server Check
                          5: DAC Server Check
                          6: Oracle Database and listener check
                          7: Check the File System
                          8: HardWare Report
			  9: Weekly Cold Backup
                          10: TSM Backup status
                          Q: Quit
     ------------------------------------------------------------------------
EOF

echo "Your Choice:"
read CHOICE
case  $CHOICE in
  1) NQS_Server_check
  ;;
  2) SAW_Server_check
  ;;
  3) Oc4j_Server_check
  ;;
  4) Informatica_Server_check
  ;;
  5) DAC_Server_check
  ;;
  6) instance_check
     ora_tns_check  
  ;;
  7) Disk_FileSystem_check
  ;;
  8) HardWare_check
  ;;
  9) /home/monitor/chkBackup.sh
  ;;
  10) /home/monitor/chkTSMBack.sh
  ;;
  Q|q) exit 
  ;;
  *) echo 'Wrong Input!'
  ;;
esac
echo
echo
echo "Hit the return key to continue"
read DUMMY
done

